import App from './App.vue'
import router from './router'
import store from './store'
import 'element-ui/lib/theme-chalk/index.css';
import './assets/css/global.css'
import axios from 'axios'
import TreeTable from 'vue-table-with-tree-grid'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import moment from 'moment'; //导入模块
//lodash工具
import _ from 'lodash'
// mavon-editre编辑器
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
Vue.prototype.$http=axios
Vue.use(mavonEditor)
Vue.prototype._ = _ 
moment.locale('zh-cn'); //设置语言 或 moment.lang('zh-cn'); 
Vue.prototype.$moment = moment;//赋值使用

Vue.component('table-tree', TreeTable)
axios.defaults.baseURL='http://47.98.113.244:8889/api/private/v1'
Vue.prototype.$http=axios
Vue.prototype.$bus=new Vue()
Vue.config.productionTip = false
Vue.use(ElementUI);
axios.interceptors.request.use(config=>{
            config.headers.Authorization=localStorage.getItem('token')
            return config
})
router.beforeEach((to, from, next) => {
  
  if (to.path === '/login'||to.path==='/register') {
    next();
  } else {
    let token = localStorage.getItem('token');
      console.log(token);
    if (token === null || token === '') {
      next('/login');
      Vue.prototype.$message({
        message:'权限不足!ε=(´ο｀*)))',
        type:'error'
      })
      
    } else {
      NProgress.start()
      next();
    }
  }
})
router.afterEach(()=>{
  console.log('323');
  NProgress.done()
})
Vue.filter('tansformDate',val=>{
  return moment(val).format('YYYY-MM-DD HH:mm:ss');

})
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
